//测试内存分布
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Func1()
{

}

void Func2()
{

}

int uninit_global_val ;//未初始化全局变量
int global_val = 20;//初始化全局变量

static int uninit_static_global_val;//未初始化的静态全局变量
static int static_global_val=20;//初始化静态全局变量



int main(int argc,char* argv[],char* envp[])
{
    //栈区
	int stack_val_1 = 10;//栈区变量
	int stack_val_2 = 20;
	int stack_val_3 = 30;
	int stack_val_4 = 40;
	printf("stack_addr1:%p\n", &stack_val_1);
	printf("stack_addr2:%p\n", &stack_val_2);
	printf("stack_addr3:%p\n", &stack_val_3);
	printf("stack_addr4:%p\n", &stack_val_4);
    printf("------------------------------------\n");

    //堆区
	int* heap_val_1 = (int*)malloc(sizeof(int));//指向堆区变量
	int* heap_val_2 = (int*)malloc(sizeof(int));
	int* heap_val_3 = (int*)malloc(sizeof(int));
	int* heap_val_4 = (int*)malloc(sizeof(int));
	printf("heap_val_1:%p\n", heap_val_1);
	printf("heap_val_2:%p\n", heap_val_2);
	printf("heap_val_3:%p\n", heap_val_3);
	printf("heap_val_4:%p\n", heap_val_4);
    printf("------------------------------------\n");



    //静态区
    static int uninit_static_local_val;//未初始化的静态局部变量
    static int static_local_val=20;//初始化静态局部变量
	printf("uninit_global_val:%p\n", &uninit_global_val);//未初始化全局变量
    printf("uninit_static_golbal_val:%p\n",&uninit_static_global_val);//未初始化的静态全局变量
    printf("uninit_static_local_val:%p\n",&uninit_static_local_val);//未初始化的静态局部变量
    printf("\n");
    printf("global_val:%p\n", &global_val);//初始化的全局变量
    printf("static_local_val:%p\n",&static_local_val);//初始化的静态局部变量
    printf("static_global_val:%p\n",&static_global_val);//初始化的静态全局变量
    printf("------------------------------------\n");


    
    //只读数据
	const char* str = "hello world";//常量字符串
	printf("only_read:%p\n", str);

    printf("user_defined_code_addr:%p\n", Func1);//自定义函数->代码段
	printf("user_defined_code_addr:%p\n", Func2);
    printf("------------------------------------\n");



    //环境变量+命令行参数
    printf("environment_val:%p\n",envp[0]);
    printf("command_addr:%p\n",argv[0]);

	return 0;
}